package org.cuatrovientos.erp.dao;



import org.cuatrovientos.erp.domain.Ciudad;
import org.cuatrovientos.erp.domain.Delegacion;
import org.cuatrovientos.erp.action.DelegacionAction;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import com.googlecode.s2hibernate.struts2.plugin.annotations.SessionTarget;
import com.googlecode.s2hibernate.struts2.plugin.annotations.TransactionTarget;

public class DelegacionDAO {
	
	@SessionTarget
	Session session;
	
	@TransactionTarget
	Transaction transaction;
	

	/**
	 * Used to save or update a user.
	 */
	public void guardarOActualizarDelegacion(Delegacion delegacion) {
		try {
			session.saveOrUpdate(delegacion);
		} catch (Exception e) {
			transaction.rollback();
			e.printStackTrace();
		}
	}

	/**
	 * Used to delete a user.
	 */
	public void eliminarDelegacion(Long id) {
		try {
			Delegacion delegacion = (Delegacion) session.get(Delegacion.class, id);
			session.delete(delegacion);
		} catch (Exception e) {
			transaction.rollback();
			e.printStackTrace();
		} 
	}
	
	/**
	 * Used to list all the users.
	 */
	@SuppressWarnings("unchecked")
	public List<Delegacion> listarDelegacions(){
		List<Delegacion> delegacions = null;
		try {
			delegacions = session.createQuery("from Delegacion").list();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return delegacions;
	}

	/**
	 * Used to list a single user by Id.
	 */
	public Delegacion listarDelegacionPorId(Long id) {
		Delegacion delegacion = null;
		try {
			delegacion = (Delegacion) session.get(Delegacion.class, id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return delegacion;
	}

}
